package ext.tianma.test;

import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.poi.POIXMLDocument;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONObject;

import ext.com.iba.IBAUtil;
import ext.tianma.MaterialClassification.ReadClassification;
import ext.tianma.bom.eco.BOMHelp;
import ext.tianma.bom.util.ClassificationUtil;
import ext.tianma.bom.util.GenericUtil;
import ext.tianma.bom.util.LWCUtil;
import ext.tianma.bom.util.StringUtil;
import wt.csm.navigation.ClassificationNode;
import wt.csm.navigation.ClassificationStruct;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.PersistenceServerHelper;
import wt.fc.QueryResult;
import wt.fc.WTObject;
import wt.folder.Folder;
import wt.folder.FolderEntry;
import wt.folder.FolderHelper;
import wt.iba.definition.ReferenceDefinition;
import wt.iba.value.IBAHolder;
import wt.iba.value.IBAReferenceable;
import wt.iba.value.ReferenceValue;
import wt.inf.container.WTContainer;
import wt.inf.container.WTContainerRef;
import wt.lifecycle.LifeCycleHelper;
import wt.lifecycle.State;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.part.LineNumber;
import wt.part.Quantity;
import wt.part.QuantityUnit;
import wt.part.Source;
import wt.part.WTPart;
import wt.part.WTPartMaster;
import wt.part.WTPartUsageLink;
import wt.pds.StatementSpec;
import wt.query.KeywordExpression;
import wt.query.QueryException;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.type.TypeDefinitionReference;
import wt.type.TypedUtility;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;
import wt.vc.VersionControlHelper;
import wt.vc.views.View;
import wt.vc.views.ViewHelper;
import wt.vc.views.ViewReference;

public class CreatePartClassificationNode implements RemoteAccess {
	// 在类型管理器中自定义的part类型
	private static String part_type = "wt.part.WTPart|cn.tianma.TwoLevelMaterial";
	private static String FPC_PCBpart_type = "wt.part.WTPart|cn.tianma.TwoLevelMaterial|cn.tianma.FPC_PCB";
	private static String BLUBpart_type = "wt.part.WTPart|cn.tianma.BLU";
	public static final String discardState = "OBSOLESCENCE";// 废弃状态
	// 产品中文件夹的路径，注意默认在文件夹前夹上Default
	private static String PartPath = "Default/AVL材料";

	public static String STATUTE_PATH = "/ptc/Windchill/codebase/ext/tianma/part/config/classIfication.xlsx";

	/**
	 * 创建一个新的部件，类似的代码可以实现修改part的基本属性
	 * 
	 * @param number
	 *            部件的编码
	 * @param PartType
	 *            部件的类型，部件在windchill中可以自定义很多中类型
	 * @return
	 * @throws WTException
	 * @throws WTPropertyVetoException
	 */
	public static QueryResult getQueryResult(Class className, String attribute, String value) throws WTException {
		QueryResult qr = null;
		try {
			QuerySpec qs = new QuerySpec(className);
			SearchCondition sc = new SearchCondition(className, attribute, SearchCondition.EQUAL, value);
			qs.appendWhere(sc);
			qr = PersistenceHelper.manager.find(qs);

		} catch (Exception e) {
			// TODO: handle exception
		}
		return qr;
	}

	public static WTPart createPartByAVL(WTObject obj) throws Exception {
		WTPart avlPart = null;
		String classIfaName = "";
		String strClasAVLName = "";
		if (obj instanceof WTPart) {
			avlPart = (WTPart) obj;
			String nodeFileName = getClassification(avlPart);
			System.out.println("nodeFileName====>>" + nodeFileName);
			classIfaName = nodeFileName.substring(nodeFileName.lastIndexOf("/") + 1);
			System.out.println("classIfaName===>>" + classIfaName);
			// strClasAVLName = nodeFileName.substring(4, nodeFileName.);
		}
		WTPart newPart = null;
		// 获取容器
		WTContainer container = null;
		QueryResult qr = getQueryResult(WTContainer.class, WTContainer.NAME, "物料库");
		while (qr.hasMoreElements()) {
			container = (WTContainer) qr.nextElement();
		}

		// 获取容器的引用
		WTContainerRef ref = ref = WTContainerRef.newWTContainerRef(container);
		// 获取文件夹
		Folder folder = wt.folder.FolderHelper.service.getFolder(PartPath, ref);

		String strPartNumber = getCascade(avlPart);
		System.out.println("strPartNumber===>>" + strPartNumber);
		String strPartName = avlPart.getName();
		System.out.println("strPartName-=====>>" + strPartName);
		wt.vc.views.View view = ViewHelper.service.getView("Design");
		ViewReference viewRef = ViewReference.newViewReference(view);

		TypeDefinitionReference typeDefinitionRef = TypedUtility.getTypeDefinitionReference(FPC_PCBpart_type);

		// 创建一个部件，编码与名称
		newPart = WTPart.newWTPart(strPartNumber, strPartName);
		// 为部件设置容器
		newPart.setContainer(container);
		// 为部件设置类型
		newPart.setTypeDefinitionReference(typeDefinitionRef);
		// 为部件设置view
		newPart.setView(viewRef);
		// 是否成品
		newPart.setEndItem(false);
		// 设置单位
		QuantityUnit unit = QuantityUnit.toQuantityUnit("PCS");
		newPart.setDefaultUnit(unit);
		// 设置来源
		Source source = Source.toSource("make");
		newPart.setSource(source);
		// 设置关联的AVL材料
		// LWCUtil.setStringIBAValue(newPart, "", avlPart.getNumber());
		// 为此部件设置存贮位置
		FolderHelper.assignLocation((FolderEntry) newPart, folder);
		// 保存部件，切忌不要保存两次。经常在调用完本方法之后习惯性的再保存一次，这样会出现错误。
		newPart = (WTPart) PersistenceHelper.manager.save(newPart);
		// 从数据库中提取part
		newPart = (WTPart) LifeCycleHelper.service.setLifeCycleState(newPart, State.INWORK);
		newPart = (WTPart) PersistenceHelper.manager.refresh(newPart);
		Map<String, String> map = getMaterialsClassification(avlPart.getNumber());
		System.out.println("map==>>" + map);
		Iterator keys = map.keySet().iterator();
		if (classIfaName != null) {
			setClassification("wt.part.WTPart", classIfaName, newPart);
		}
		newPart = (WTPart) PersistenceHelper.manager.refresh(newPart);
		System.out.println("newPart=====>>>" + newPart.getNumber());
		// PartIBAHelper partIba = new PartIBAHelper(newPart);
		while (keys.hasNext()) {
			String key = (String) keys.next();
			String value = map.get(key);
			LWCUtil.setStringIBAValue(newPart, key, value);// 对应上POL料号
		}

		// //添加bomlink关系
		WTPart parentPart = BOMHelp.getPart("0000094684", "", "");
		WTPartMaster childPartMaster = (WTPartMaster) avlPart.getMaster();
		createWTPartUsageLink(parentPart, childPartMaster, null);

		return newPart;
	}

	/**
	 * 
	 * @param classificationType
	 *            wt.part.WTPart
	 * @param classificationPath
	 *            name
	 * @param holder
	 *            pbo
	 * @throws Exception
	 */
	public static void setClassification(String classificationType, String classificationPath, IBAHolder holder)
			throws Exception {

		ReferenceDefinition refDefinition = getReferenceDefinition(classificationType);
		if (refDefinition == null)
			throw new Exception("No Classification Structure Found for " + classificationType);

		// IBAReferenceable referenceable = getClassificationNodeByPath(
		// classificationType, classificationPath);
		IBAReferenceable referenceable = getClassificationNodeByName(classificationPath);
		if (referenceable == null)
			throw new Exception("No Classification Path " + classificationPath + " found for " + classificationType);

		ReferenceValue refValue = ReferenceValue.newReferenceValue(refDefinition, holder, referenceable);
		PersistenceHelper.manager.save(refValue);

	}

	public static ClassificationNode getClassificationNodeByName(String classificationPath) throws Exception {
		QuerySpec spec = new QuerySpec(ClassificationNode.class);
		SearchCondition condition = new SearchCondition(ClassificationNode.class, ClassificationNode.NAME,
				SearchCondition.EQUAL, classificationPath);
		spec.appendWhere(condition, new int[0]);
		QueryResult result = PersistenceHelper.manager.find((StatementSpec) spec);
		while (result.hasMoreElements())
			return (ClassificationNode) result.nextElement();
		return null;
	}

	// wt.part.WTPart
	public static ReferenceDefinition getReferenceDefinition(String classificationType) throws Exception {
		QuerySpec spec = new QuerySpec(ClassificationStruct.class);
		SearchCondition condition = new SearchCondition(ClassificationStruct.class, ClassificationStruct.CLASS_NAME,
				SearchCondition.EQUAL, classificationType);
		spec.appendWhere(condition, new int[0]);
		QueryResult result = PersistenceHelper.manager.find((StatementSpec) spec);
		while (result.hasMoreElements()) {
			ClassificationStruct struct = (ClassificationStruct) result.nextElement();
			return struct.getRefDef();
		}
		return null;
	}

	public static String RemoteMethod(String partNumber) throws RemoteException, InvocationTargetException {
		String CLASSNAME = (CreatePartClassificationNode.class).getName();
		Class argTypes[];
		Object svrArgs[];
		argTypes = (new Class[] { String.class });
		svrArgs = (new Object[] { partNumber });
		return (String) RemoteMethodServer.getDefault().invoke("getClassificationNode", CLASSNAME, null, argTypes,
				svrArgs);
	}

	/*
	 * 获取部件的分类节点
	 */
	@SuppressWarnings("deprecation")
	public static ClassificationNode getClassificationNode(WTPart part) {
		ClassificationNode classNode = null;
		QuerySpec queryspec;
		try {
			queryspec = new QuerySpec(wt.iba.value.ReferenceValue.class);
			queryspec.appendSearchCondition(new SearchCondition(wt.iba.value.ReferenceValue.class,
					"theIBAHolderReference.key", "=", part.getPersistInfo().getObjectIdentifier()));

			QueryResult queryresult = PersistenceHelper.manager.find(queryspec);
			while (queryresult.hasMoreElements()) {
				wt.iba.value.ReferenceValue value = (ReferenceValue) queryresult.nextElement();
				Persistable obj = value.getIBAReferenceableReference().getObject();
				if (obj instanceof ClassificationNode) {
					classNode = (ClassificationNode) obj;
				}
			}
		} catch (QueryException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
		return classNode;
	}

	/*
	 * 获取部件分类节点的全路径名称，包括父节点名 如：电控零部件 \结构件 \成品电控柜
	 */
	@SuppressWarnings("deprecation")
	public static String getClassification(WTPart part) {
		ClassificationNode classNode = null;
		QuerySpec queryspec;
		try {
			queryspec = new QuerySpec(wt.iba.value.ReferenceValue.class);
			queryspec.appendSearchCondition(new SearchCondition(wt.iba.value.ReferenceValue.class,
					"theIBAHolderReference.key", "=", part.getPersistInfo().getObjectIdentifier()));

			QueryResult queryresult = PersistenceHelper.manager.find(queryspec);
			while (queryresult.hasMoreElements()) {
				wt.iba.value.ReferenceValue value = (ReferenceValue) queryresult.nextElement();
				Persistable obj = value.getIBAReferenceableReference().getObject();
				if (obj instanceof ClassificationNode) {
					classNode = (ClassificationNode) obj;
				}
			}
		} catch (QueryException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}

		// Debug.P("--------------------------------->>>>>>>>>>>>>>> classNode : " +
		// classNode);
		String classification = "";
		if (classNode != null) {
			ClassificationNode parentNode = null;
			List<ClassificationNode> classNodeLink = new ArrayList<ClassificationNode>(); // 用于存放部件的分类层级
			classNodeLink.add(classNode);
			// 倒序遍历上层分类
			while ((parentNode = classNode.getParent()) != null) {
				classNodeLink.add(parentNode);
				classNode = parentNode;
			}

			/**
			 * 获取完成的分类路径，例如：标准件/紧固件
			 */
			int linkSize = classNodeLink.size();
			StringBuffer classificationBuffer = new StringBuffer("");

			for (int i = linkSize - 1; i >= 0; i--) {
				ClassificationNode node = classNodeLink.get(i);
				classificationBuffer.append(node.getName());
				classificationBuffer.append("/");
			}
			classification = classificationBuffer.toString();
			if (classification.endsWith("/")) {
				classification = classification.substring(0, classification.length() - 1);
			}
		}
		return classification;
	}

	/**
	 * 根据part的编号获取对应的WTPartMaster
	 */
	public static WTPartMaster getWTPartMasterBYNumber(String number)

	{
		WTPartMaster master = null;
		try {

			QuerySpec qsMaster = new QuerySpec(WTPartMaster.class);
			SearchCondition sc = new SearchCondition(WTPartMaster.class, WTPartMaster.NUMBER, SearchCondition.EQUAL,
					number);
			qsMaster.appendSearchCondition(sc);
			QueryResult qrMaster = PersistenceHelper.manager.find(qsMaster);
			if (qrMaster.hasMoreElements()) {

				master = (WTPartMaster) qrMaster.nextElement();
			}

		} catch (WTException e) {
			e.printStackTrace();
		}
		return master;

	}

	/**
	 * 根据WTPartMaster获得最新版WTPart
	 * 
	 */
	public static WTPart getLatestPart(WTPartMaster partMaster) throws Exception {
		WTPart part = null;
		if (partMaster != null) {
			QueryResult qr = VersionControlHelper.service.allVersionsOf(partMaster);
			if (qr != null && qr.hasMoreElements()) {
				part = (WTPart) qr.nextElement();
			}
		}
		return part;
	}

	/**
	 * 获取分类属性值
	 * 
	 * @param number
	 * @return
	 */
	public static Map<String, String> getMaterialsClassification(String number) {
		JSONObject result = new JSONObject();
		Map<String, String> maps = new HashMap<String, String>();
		try {
			WTPart part = GenericUtil.getPart(number, "");
			if (part == null) {
				result.put("datalist", "");
			}
			// String classtype = (String) LWCUtil.getValue(part, "SemiFinishedGoodType");
			// System.out.println("=====getMaterialsClassification classtype:" + classtype);

			List<HashMap<String, String>> list = ClassificationUtil.getNodeIBAByPart2(part);
			JSONObject object = new JSONObject();
			for (HashMap<String, String> map : list) {
				String displayname = map.get("displayname");
				String value = map.get("value");
				String key = map.get("key");
				System.out.println("====displayname:" + displayname + "==key:" + key + "---value:" + value);
				object.put(displayname, value == null ? "" : value);
				maps.put(key, value);
			}
			result.put("datalist", object);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("===getMaterialsClassification Exception:" + e);
			e.printStackTrace();
		}
		return maps;
	}

	/***
	 * 读取exce分辨率及分辨率代码
	 * 
	 * @return
	 * @throws WTException
	 */
	public static String getCascade(WTPart part) throws WTException {
		String partNumber = "";
		String Orderno = null;
		System.out.println("===>>start==>>action===>>");
		InputStream is = null;
		Workbook wb = null;
		Workbook workbook = null;
		try {
			System.out.println("CASCADE_PATH===>>" + STATUTE_PATH);
			is = new FileInputStream(STATUTE_PATH);

			System.out.println("=====>>>" + STATUTE_PATH);
			if (!is.markSupported()) {
				is = new PushbackInputStream(is, 8);
			}

			if (POIFSFileSystem.hasPOIFSHeader(is)) {
				// 2003及以下
				wb = new HSSFWorkbook(is);
			} else if (POIXMLDocument.hasOOXMLHeader(is)) {
				// 2007及以上
				wb = new XSSFWorkbook(is);
			} else {
				// 不是Excel
				throw new WTException("Incorrect configuration file path.");
			}

			workbook = wb;

			Sheet sheet = workbook.getSheetAt(0);
			Row row;
			Cell cell1, cell2, cell;
			String tempVal;

			// 第一行为表头，从第二行开始遍历
			for (int i = 2, rowNum = sheet.getLastRowNum(); i <= rowNum; i++) {
				if ((row = sheet.getRow(i)) != null) {
					// 遍历列
					String finishedGoodResolutionCode = "";
					String fbl_W = "";
					int cellNum = row.getLastCellNum();
					String str = "";
					for (int j = 0; j <= cellNum; j++) {
						cell = row.getCell(j);
						cell1 = row.getCell(0);
						cell2 = row.getCell(1);
						if (cell1 == null || (tempVal = cell1.getStringCellValue()) == null || cell2 == null
								|| (tempVal = cell2.getStringCellValue()) == null) {
							str = "";
						} else {
							System.out.println("cell======>>"+cell.getStringCellValue());
							System.out.println("cell1======>>"+cell1.getStringCellValue());
							System.out.println("cell2======>>"+cell2.getStringCellValue());
							
							
							
							finishedGoodResolutionCode = cell1.getStringCellValue();
							fbl_W = cell2.getStringCellValue();
							String nodeFileName = getClassification(part);
							// System.out.println("nodeFileName====>>" + finishedGoodResolutionCode);
							if (finishedGoodResolutionCode.equals(nodeFileName)) {
								System.out.println("===>>start===");
								partNumber = fbl_W;
							}
						}
					}

				}
			}
			// 生成六位流水碼

			String maxOrderno = getAVLMaterial(partNumber); // 从数据库查询出的最大编号
			System.out.println("maxOrderno=" + maxOrderno);
			int endNum = Integer.parseInt(maxOrderno); // 把String类型的0001转化为int类型的1
			System.out.println("endNum=" + endNum);
			int tmpNum = 100000 + endNum + 1; // 结果1000002
			System.out.println("tmpNum=" + tmpNum);
			Orderno = partNumber + subStr("" + tmpNum, 1);// 把10002首位的1去掉，再拼成NO201601260002字符串
			System.out.println("Orderno====>>" + Orderno);
			System.out.println("fblMap====>>>" + partNumber);
			return Orderno;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			throw new WTException(e);
		} catch (IOException e) {
			e.printStackTrace();
			throw new WTException(e);
		} finally {
			close(is);
		}
	}

	public static String subStr(String str, int start) {
		if (str == null || str.equals("") || str.length() == 0)
			return "";
		if (start < str.length()) {
			return str.substring(start);
		} else {
			return "";
		}

	}

	/**
	 * 关闭资源
	 * 
	 * @param closeable
	 */
	public static void close(Closeable closeable) {
		try {
			if (closeable != null) {
				closeable.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 创建UsageLink方法
	 * 
	 * @param parentPart
	 * @param childPartMaster
	 * @param lineNumber
	 * @param hashtable
	 * @param Yield
	 *            良率
	 * @throws WTException
	 */
	private static void createWTPartUsageLink(WTPart parentPart, WTPartMaster childPartMaster, Hashtable hashtable) {
		if (parentPart == null || childPartMaster == null) {
			return;
		}
		WTPartUsageLink usageLink;
		try {
			parentPart = (WTPart) GenericUtil.checkout(parentPart);
			usageLink = WTPartUsageLink.newWTPartUsageLink(parentPart, childPartMaster);
			GenericUtil.checkin(parentPart);
			parentPart = (WTPart) PersistenceHelper.manager.refresh(parentPart);
		} catch (WTException e) {
			System.out.println("ERROR  createWTPartUsageLink: parentPart," + parentPart.getNumber()
					+ ";childPartMaster," + childPartMaster.getNumber());
			e.printStackTrace();
		} catch (WTPropertyVetoException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

	}

	public static void createUserLinkByPart() {
		WTPart parentPart;
		try {
			parentPart = BOMHelp.getPart("0000094684", "", "");

			WTPart childPart = BOMHelp.getPart("S140200002", "", "");
			WTPartMaster childPartMaster = (WTPartMaster) childPart.getMaster();
			WTPartUsageLink newlink = WTPartUsageLink.newWTPartUsageLink(parentPart, childPartMaster);
			double quanty = Double.parseDouble("1");
			QuantityUnit qu = null;
			if (childPartMaster != null) {
				qu = childPartMaster.getDefaultUnit();
			}
			Quantity qtity = Quantity.newQuantity(quanty, qu);
			newlink.setQuantity(qtity);
			PersistenceServerHelper.manager.insert(newlink);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 设置usageLink的单位数量
	 * 
	 * @param quantity
	 * @param usageLink
	 */
	private static void setQuantity(Quantity quantity, WTPartUsageLink usageLink) {
		if (quantity != null && !quantity.equals("")) {
			usageLink.setQuantity(quantity);
		}
	}

	/**
	 * 创建一个usageLink关系对象并且为其行号复制
	 * 
	 * @param lineNumber
	 * @param usageLink
	 * @throws WTException
	 */
	private static void setLineNumber(String lineNumber, WTPartUsageLink usageLink) throws WTException {
		if (lineNumber != null && !lineNumber.equals("")) {

			try {
				long lineNumberValue = Long.parseLong(lineNumber);
				LineNumber newLineNumber = LineNumber.newLineNumber(lineNumberValue);
				usageLink.setLineNumber(newLineNumber);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	

	public static String getAVLMaterial(String ifinodeClassName) {
		System.out.println("======>>>>star");
		List<Integer> list = new ArrayList<Integer>();
		 String MaxStr = "";
		try {
			QuerySpec qs = new QuerySpec();
			int docIndex = qs.appendClassList(WTPart.class, true);
			View view = ViewHelper.service.getView("Design");

			// 增加过滤条件：iba属性存在值
//			TypeDefinitionReference clientType = ClientTypedUtility.getTypeDefinitionReference(FPC_PCBpart_type);
//			SearchCondition scOther = new SearchCondition(WTPart.class,
//					Typed.TYPE_DEFINITION_REFERENCE + "." + TypeDefinitionReference.KEY + "."
//							+ TypeDefinitionForeignKey.BRANCH_ID,
//					SearchCondition.EQUAL, clientType.getKey().getBranchId());
//			qs.appendWhere(scOther, new int[] { 0 });
//			qs.appendAnd();
			SearchCondition scState = new SearchCondition(WTPart.class, WTPart.LIFE_CYCLE_STATE,
					SearchCondition.NOT_EQUAL, discardState);
			qs.appendWhere(scState, new int[] { 0 });
			qs.appendAnd();
			qs.appendWhere(new SearchCondition(new KeywordExpression("A0.latestiterationinfo"), SearchCondition.EQUAL,
					new KeywordExpression("1")));
			QueryResult qr = PersistenceHelper.manager.find(qs);
			System.out.println("======>>>>start44===>>updateIBAValue" + qs);
			System.out.println("======>>>>start55===>>updateIBAValue" + qr.size());
			int count = 1;
			while (qr.hasMoreElements()) {
				System.out.println("count==>>" + count);
				Object obj[] = (Object[]) qr.nextElement();
				if (obj[0] instanceof WTPart) {
					WTPart part = (WTPart) obj[0];
					System.out.println("===>>>"+part.getNumber());
					if (part.getNumber().startsWith(ifinodeClassName)) {
						String partNumber = part.getNumber().substring(part.getNumber().length() - 6);
						String strNumber = "1" + partNumber;
						int number = Integer.parseInt(strNumber);
						list.add(number);
					}
				}
			}
			int max = 0;
			for (int i = 0; i < list.size(); i++) {
				 list.get(0);
				if (list.get(i) > max) {
					max = list.get(i);
				 }
			 }
			MaxStr = CreatePartClassificationNode.subStr("" + max, 1);
			System.out.println("MaxStr====>>"+MaxStr);
		} catch (QueryException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (WTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return MaxStr;
	}
	

}
